# Maintainer: Jelle van der Waa <jelle@archlinux.org>

pkgname=dnf
pkgver=4.15.0
pkgrel=2
pkgdesc="Package manager forked from Yum, using libsolv as a dependency resolver"
arch=('any')
url="https://github.com/rpm-software-management/$pkgname"
license=('GPL2')
depends=('libdnf' 'libcomps'
         'python' 'python-gpgme' 'rpm-tools')
makedepends=('bash-completion' 'cmake' 'python-sphinx')
optdepends=('unbound: for gpgkey_dns_verification option')
backup=("etc/$pkgname/automatic.conf"
        "etc/$pkgname/$pkgname.conf"
        "etc/$pkgname/aliases.d/zypper.conf"
        "etc/$pkgname/protected.d/$pkgname.conf"
        "etc/$pkgname/protected.d/yum.conf"
        "etc/libreport/events.d/collect_$pkgname.conf"
        "etc/logrotate.d/$pkgname")
options=('!emptydirs')
source=("$url/archive/$pkgver/$pkgname-$pkgver.tar.gz" "arch-release-ver.patch")
sha256sums=('756a6655729c31742388bdc14ceb4e6a1eee535ef815cd3cfffab5ce53685418'
            '503544681d192a8e844012c58a69321eab19682fec9ecc9cb5ca93cedfe8a47e')

prepare() {
  cd "$pkgname-$pkgver"

  # sphinx-build-3 does not exist on Arch Linux,
  # use sphinx-build instead
  sed -e 's/sphinx-build-3/sphinx-build/' \
      -i doc/CMakeLists.txt

  # HACK: arch has no RELEASE_VER in /etc/os-release but setting it still makes `dnf.rpm.detect_releasever` returns None.
  # Set it to the latest Fedora release to make dnf at least work.
  patch -Np1 -i $srcdir/arch-release-ver.patch
}

build() {
  cd "$pkgname-$pkgver"

  cmake -B build \
        -DCMAKE_INSTALL_PREFIX=/usr \
        -DPYTHON_DESIRED=3

  make -C build
  make -C build doc-man
}

check() {
  cd "$pkgname-$pkgver"

  # Fails because Arch Linux does not support C.UTF-8 locale
  make -n -C build ARGS="--output-on-failure" test
}

package() {
  cd "$pkgname-$pkgver"

  make -C build DESTDIR="$pkgdir/" install

  install -Dp -m644 README.rst "$pkgdir/usr/share/doc/$pkgname/README.rst"

  rm "$pkgdir/usr/share/man/man8/yum.8" \
     "$pkgdir/usr/share/man/man5/yum.conf.5" \
     "$pkgdir/usr/share/man/man1/yum-aliases.1" \
     "$pkgdir/usr/share/man/man8/yum-shell.8"
  ln -s $pkgname-3 "$pkgdir/usr/bin/$pkgname"
  ln -s $pkgname-automatic-3 "$pkgdir/usr/bin/$pkgname-automatic"

  rm "$pkgdir/etc/$pkgname/$pkgname-strict.conf"
}
